package com.zillion.web.controller.certificate;

import com.zillion.certificate.domain.HealthCertificate;
import com.zillion.certificate.service.IHealthCertificateService;
import com.zillion.common.annotation.Log;
import com.zillion.common.core.controller.BaseController;
import com.zillion.common.core.domain.AjaxResult;
import com.zillion.common.core.page.TableDataInfo;
import com.zillion.common.enums.BusinessType;
import com.zillion.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 体检健康证Controller
 *
 * @author zillion
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/health/certificate")
public class HealthCertificateController extends BaseController
{
    @Autowired
    private IHealthCertificateService healthCertificateService;

    /**
     * 查询体检健康证列表
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthCertificate healthCertificate)
    {
        startPage();
        List<HealthCertificate> list = healthCertificateService.selectHealthCertificateList(healthCertificate);
        return getDataTable(list);
    }

    /**
     * 导出体检健康证列表
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:export')")
    @Log(title = "体检健康证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthCertificate healthCertificate)
    {
        List<HealthCertificate> list = healthCertificateService.selectHealthCertificateList(healthCertificate);
        ExcelUtil<HealthCertificate> util = new ExcelUtil<HealthCertificate>(HealthCertificate.class);
        util.exportExcel(response, list, "体检健康证数据");
    }

    /**
     * 获取体检健康证详细信息
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthCertificateService.selectHealthCertificateById(id));
    }

    /**
     * 新增体检健康证
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:add')")
    @Log(title = "体检健康证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthCertificate healthCertificate)
    {
        return toAjax(healthCertificateService.insertHealthCertificate(healthCertificate));
    }

    /**
     * 修改体检健康证
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:edit')")
    @Log(title = "体检健康证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthCertificate healthCertificate)
    {
        return toAjax(healthCertificateService.updateHealthCertificate(healthCertificate));
    }

    /**
     * 删除体检健康证
     */
    @PreAuthorize("@ss.hasPermi('health:certificate:remove')")
    @Log(title = "体检健康证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthCertificateService.deleteHealthCertificateByIds(ids));
    }
}
